package cn.com.zetatech.loader.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * @author jian.chen@zetatech.com.cn
 * @Description TODO
 * @Date 2024/8/15 8:58
 */
@Slf4j
@Component
@EnableScheduling
public class CleanUpLogTasks {

//    @Scheduled(fixedDelay = 10000) // 10 seconds
    public void cleanOldData() {
        LocalDate oneMonthAgo = LocalDate.now().minusMonths(1);
        Date dateOneMonthAgo = Date.from(oneMonthAgo.atStartOfDay(ZoneId.systemDefault()).toInstant());

        log.info("Old data before {} has been cleaned up.", dateOneMonthAgo);

    }

//    @Scheduled(cron = "*/10 * * * * *") // Every 10 seconds
    public void performTask() {
        System.out.println("Task executed at " + System.currentTimeMillis());
    }
}